package com.shenfa.dao.compose;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;

public class MakeComposeDao {

	@Autowired
	private SqlMapClient sqlMapClient;
	
	/**
	 * 根据用户ID查询XML合成文件
	 * 
	 * XML合成成功，查询后修改状态为账单合成中
	 * @param userid
	 * @return
	 */
	@SuppressWarnings({ "finally", "unchecked" })
	public List<Map<String,String>> getListXmlByUserid(String userid){
		List<Map<String,String>> xmlLog = null;
		try {
			xmlLog = sqlMapClient.queryForList("makexml.getListXml",userid);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			return xmlLog;
		}
	}
	
	/**
	 * 根据XML文件名合成账单
	 * 
	 * @param fileName
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "finally" })
	public Map<String, String> getXmlByFileName(HashMap map) {
		Object obj = null;
		try {
			obj = sqlMapClient.queryForObject("makexml.getObjectXml",map);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			return null==obj? null:(Map<String, String>)obj;
		}
	}
	
	/**
	 * 修改XML日志状态（特殊）
	 * @return 0成功，1失败
	 */
	public int updXmlLogState(Map<String,String> xmlLog){
		try {
			sqlMapClient.update("makexml.updXmlLog",xmlLog);
			return 0;
		} catch (SQLException e) {
			e.printStackTrace();
			return 1;
		}
	}
	
	/**
	 * 修改XML日志状态（正常）
	 * @return 0成功，1失败
	 */
	public int updComposeLogState(Map<String,String> map){
		try {
			sqlMapClient.update("makexml.updComposeLog", map);
			return 0;
		} catch (SQLException e) {
			e.printStackTrace();
			return 1;
		}
	}

}
